package www.baidu;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.UnknownHostException;

public class textScoket {
	private static ServerSocket serverSocket;

	public static void main(String[] args) throws IOException {
		serverSocket = new ServerSocket(2999);
		System.out.println("start to listen at part 2999...");
		Socket clientSocket =serverSocket.accept();
	    String cipString =clientSocket.getInetAddress().getHostAddress();
	    System.out.println(cipString);
		
	    BufferedReader inBufferedReader;
		PrintWriter outPrintWriter;
		
		inBufferedReader=new BufferedReader (new InputStreamReader(clientSocket.getInputStream()));
		outPrintWriter = new PrintWriter(clientSocket.getOutputStream());
		
		String text;
		while((text=inBufferedReader.readLine())!=null){
			if(text.equals("bye")){
				break;
			}
			outPrintWriter.println(text);
			outPrintWriter.flush();
			System.out.println(text);
		}
		inBufferedReader.close();
		outPrintWriter.close();
		serverSocket.close();
		
	}
		
}
